﻿namespace NetFx.SMIL.Definitions
{
  using System;
  using System.Text;
  using System.Collections;

  using System.Reflection;
  using System.Reflection.Emit;
  using System.Runtime.InteropServices;

  using System.Diagnostics;
  using System.Diagnostics.CodeAnalysis;
  using System.Diagnostics.SymbolStore;
  using System.Security;
  using System.Security.Permissions;

  using NetFx.MSIL;
  using NetFx.MSIL.Headers;

  public class MethodDefinition : ComplexDefinition
  {
    #region Statics
    public static MethodDefinition of(string name)
    {
      return new MethodDefinition(name);
    }
    #endregion
    #region Fields
    protected string returnType = null;
    #endregion
    #region Properties
    public virtual MethodHeader InstanceHeader
    {
      get
      {
        return this.header as MethodHeader;
      }
    }
    public virtual string ReturnType
    {
      get
      {
        return this.returnType;
      }
      set
      {
        this.returnType = value;
      }
    }
    public virtual MethodAttributes Attributes
    {
      get
      {
        return this.InstanceHeader.Attributes;
      }
      set
      {
        this.InstanceHeader.Attributes = value;
      }
    }
    public virtual bool IsPInvoke
    {
      get
      {
        return this.InstanceHeader.IsPInvoke;
      }
      set
      {
        this.InstanceHeader.IsPInvoke = value;
      }
    }
    public virtual bool IsConstructor
    {
      get
      {
        return this.InstanceHeader.IsConstructor;
      }
      set
      {
        this.InstanceHeader.IsConstructor = value;
      }
    }
    public virtual string DllName
    {
      get
      {
        return this.InstanceHeader.DllName;
      }
      set
      {
        this.InstanceHeader.DllName = value;
      }
    }
    public virtual string EntryName
    {
      get
      {
        return this.InstanceHeader.EntryName;
      }
      set
      {
        this.InstanceHeader.EntryName = value;
      }
    }
    public virtual IList ParameterDefinitions
    {
      get
      {
        return this.Definitions;
      }
    }
    public virtual CharSet NativeCharSet
    {
      get
      {
        return this.InstanceHeader.NativeCharSet;
      }
      set
      {
        this.InstanceHeader.NativeCharSet = value;
      }
    }
    public virtual CallingConvention NativeCallingConvertion
    {
      get
      {
        return this.InstanceHeader.NativeCallingConvertion;
      }
      set
      {
        this.InstanceHeader.NativeCallingConvertion = value;
      }
    }
    public virtual CallingConventions CallingConvertion
    {
      get
      {
        return this.InstanceHeader.CallingConvertion;
      }
      set
      {
        this.InstanceHeader.CallingConvertion = value;
      }
    }

    #endregion
    #region Constructors
    public MethodDefinition(string name)
      : this(MethodHeader.of(name))
    {

    }
    public MethodDefinition(MethodHeader header)
      : base(header)
    {

    }
    #endregion
    #region Methods
    public virtual ParameterDefinition DefineParameter(string name)
    {
      return this.AddDefinition(ComplexDefinition.CreateParameterDefinition(name))
        as ParameterDefinition;
    }


    protected override void Resolve(ComplexDefinition container)
    {
      //TODO:
      //Resolve parameter defintions to parameters!

    }
    #endregion
  }

}